package com.javaee.exep3.utils;

import com.sun.jndi.toolkit.url.Uri;
import lombok.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import java.net.URI;

/**
 * @author: lzh
 */
public class HTTPUtil {


    public static Resource sendHttp(String url) {
        URI uri = UriComponentsBuilder.fromUriString(url).build(42);
        RequestEntity<Void> requestEntity = RequestEntity.get(uri)
                .header("User-Agent", "666")
                .build();
        ResponseEntity<Resource> response = new RestTemplate().exchange(requestEntity, Resource.class);
        return response.getBody();
    }
}
